<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

<!-- 导入jquery核心类库 -->
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/jquery-1.8.3.js"></script>
<!-- 导入easyui类库 -->
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/ext/portal.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/css/default.css">	
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/ext/jquery.portal.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/ext/jquery.cookie.js"></script>
<script
	src="${pageContext.request.contextPath }/js/easyui/locale/easyui-lang-zh_CN.js"
	type="text/javascript"></script>
		
<script type="text/javascript">

function GetQueryString(name)
{
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
}

	$(function(){
		$("body").css({visibility:"visible"});
		
		var customerID = GetQueryString("customerID");
		
		getCustomerInfo(customerID);
 		initDatagrid();
		initBtn();
		initEditWindow();

	});
	
	
	function initEditWindow(){
		$('#editDataWindow').window({
	           title: '修改测量数据',
	           width: 400,
	           modal: true,
	           shadow: true,
	           closed: true,
	           height: 300,
	           resizable:true,
   
	           
	       });
	}
	
	function getCustomerInfo(customerID){
		//$(selector).get(url,data,success(response,status,xhr),dataType)
	    $.get("${pageContext.request.contextPath}/customer/page.findByID.ashx?customerID="+customerID, function(data){
	    	
 	    	$("#customerName").html(data.customerName);
			$("#customerSex").html(data.customerSex==0?'男':'女');
			$("#customerAge").html(data.customerAge);
			$("#customerTel").html(data.customerTel);
			$("#customerCom").html(data.customerCom);
			$("#customerDep").html(data.customerDep);
			$("#customerDuty").html(data.customerDuty);
	 		$("#customerBeiZhu").html(data.customerBeiZhu);
			$("#customerIndex").html(data.customerIndex);
	    	
 		  });
		
	}
	
	function initBtn(){
		$('#return').click(doReturn);
		
		$('#editData').click(doEdit);
		$('#save').click(doSave);

	}
	
	function doSave(){
 		//提交表单
	 
 
				// 校验
				if($('#sform').form('validate')){
					// 1 、获得form 数据
					var params = $('#sform').serialize();
  
					// 2、将数据发送给服务器 
					$.post("${pageContext.request.contextPath}/customer/page.updateScandata.ashx", params , function(data){
						if(data == "success"){
							// 成功
							$.messager.alert('消息','操作成功 ','info');
							// 关闭窗口
							$('#editDataWindow').window('close');
							// 清除表单数据
							$("input[name='id']").val('');
							$('#editDataWindow').form('clear');
							$('#editDataWindow *').trigger('blur');// 离焦
							
							// 刷新表格数据 
							$('#grid').datagrid('reload');
						}else{
							$.messager.alert('消息','操作失败 ','info');
						}
							
					});
				}
				
			 
	}
	
	function doEdit(){
		var rowData = $('#grid').datagrid('getSelected');  
        
        if (rowData == null) {  
            $.messager.alert("提示", "请选择要修改的行！", "info");  
        } else{
      
			 $("#id").val(rowData.sid); 
			 $("#shuzhi").val(rowData.shuzhi); 
			 $("#category").html(rowData.category); 
			 $("#typename").html(rowData.typename); 
 
			$("#editDataWindow").window('open').show() ;
         } 
	}
	
	function doReturn(){
		 
		location.href="${pageContext.request.contextPath}/page.customerdata.ashx?pcode="+GetQueryString("hetongSerial");

 	}
	
	function initDatagrid(){
		//定义列
		var columns = [ [ 
		{
		field : 'category',
		title : '品类',
		width : 120,	
	},{
		field : 'typename',
		title : '项目',
		width : 120,	
	}, {
		field : 'shuzhi',
		title : '数值',
		width : 120,
	} ] ];
		
 

		// 收派标准数据表格
		$('#grid').datagrid( {
			toolbar : '#tb',
			iconCls : 'icon-forward',
			fit : true,
			border : false,
			rownumbers : true,
			singleSelect:true,
			striped : true,
			url : "${pageContext.request.contextPath}/customer/page.listScandataByID.ashx?customerID="+GetQueryString("customerID"),
			idField : 'id',
			columns : columns,
			pageList: [20,50,100],
			pagination:true,
			 view:myview,
			emptyMsg:"<font size=3>暂无记录</font>", 
		 
	       
			
		});
	}
	
	var myview = $.extend({},$.fn.datagrid.defaults.view,{
		onAfterRender:function(target){
			$.fn.datagrid.defaults.view.onAfterRender.call(this,target);
			var opts = $(target).datagrid('options');
			var vc = $(target).datagrid('getPanel').children('div.datagrid-view');
			vc.children('div.datagrid-empty').remove();
			if (!$(target).datagrid('getRows').length){
				var d = $('<div class="datagrid-empty"></div>').html(opts.emptyMsg || 'no records').appendTo(vc);
				d.css({
					position:'relative',
					left:0,
					top:50,
					width:'100%',
					textAlign:'center'
				});
			}
		}
	});
	
	
 
	
	 
	
 
	
 	
	function formatterDate(value){
		if(value==''||null==value){
			return '';
		}
		var now = new Date(parseInt(value) * 1000);  
		var year=now.getYear()+1900; 
		var month=now.getMonth()+1; 
		var date=now.getDate(); 
		var hour=now.getHours(); 
		var minute=now.getMinutes();
		minute= (minute > 9) ? minute=minute : minute='0'+minute;
		//var second=now.getSeconds(); 
		return year+"-"+month+"-"+date+" "+hour+":"+minute; 
	}
</script>	
</head>

<body class="easyui-layout" style="visibility:hidden;">
	<div region="north" style="height:31px;overflow:hidden;" split="false" border="false" >
		<div class="datagrid-toolbar">
			<a id="return" icon="icon-undo" href="#" class="easyui-linkbutton" plain="true" >返回</a>
			
		</div>
	</div>
    <div region="center" style="overflow:auto;padding:5px;" border="false">
        
 

				 <table id="buyermessage_table" type="hidden" class="table-edit"  width="95%" align="center">
           		<tr class="title"><td colspan="6">基本信息</td></tr>
            
            	<tr>
	           		<td >编号:</td>
	           		<td id="customerIndex"> </td>
					<td>姓名:</td>
					<td id="customerName"></td>
				</tr>  	 
				<tr>
					<td >性别:</td>
	           		<td id="customerSex"> </td>
	           		<td >部门:</td>
	           		<td id="customerDep"> </td>
				</tr> 
				<tr>
					<td>单位:</td>
	           		<td  id="customerCom"> </td>
	           		<td>职务:</td>
	           		<td id="customerDuty"></td>
				</tr> 
				
				<tr>
					<td>电话:</td>
	           		<td id="customerTel"> </td>
	           		<td>年龄:</td>
	           		<td id="customerAge"></td>
				</tr> 
				
					<tr>
					<td id="customerBeiZhu">备注:</td>
	           		<td ></td>
	           		<td></td>
	           		<td></td>
				</tr> 
			</table>
			
	 
			
			 <table class="table-edit"  width="95%" align="center">
           		<tr class="title"><td colspan="6">测量数据</td></tr>
			</table>
			
			<div style="height:70%;width:95%; margin:0 auto;" >
				<table  id="grid"></table>
			</div>
			<div id="tb" style="padding:5px;height:auto">
				<div style="margin-bottom:5px">
						 <a href="#"  id="editData" class="easyui-linkbutton" iconCls="icon-edit">编辑</a> 
					</div>
			</div>
			
			<div class="easyui-window" title="分场详情" id="editDataWindow" collapsible="false" minimizable="false" maximizable="false" style="top:50px;left:200px">
		<div region="north" style="height:31px;overflow:hidden;" split="false" border="false" >
			<div class="datagrid-toolbar">
				<a id="save" icon="icon-save" href="#" class="easyui-linkbutton" plain="true" >保存</a>
			</div>
		</div>
		<div region="center" style="overflow:auto;padding:5px;" border="false">
			<form id="sform" enctype='application/json'>
				<table class="table-edit" width="80%" align="center">
					<tr class="title">
						<td colspan="4">修改测量数据</td>
					</tr>

		
			 
					<input id="id" name="id" type="hidden" class="easyui-validatebox"/>
					<tr>
					
 
						<td>品类:</td>
						<td id ="category"> </td>
					</tr>
						<tr>
						<td>项目名:</td>
						<td id="typename"> </td>
					</tr>
						<tr>
						<td>项目值:</td>
						<td><input name="shuzhi" id="shuzhi" type="text" class="easyui-validatebox" required="true"  /></td>
					</tr>
					
					 
					
					</table>
			</form>
		</div>
	</div>
			
			
			
          
	</div>
</body>
</html>